package javax.activation;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

class SecuritySupport {

    class AnonymousClass2 implements PrivilegedExceptionAction {
        private final /* synthetic */ Class val$c;
        private final /* synthetic */ String val$name;

        AnonymousClass2(Class cls, String str) {
            this.val$c = cls;
            this.val$name = str;
        }

        public Object run() throws IOException {
            return this.val$c.getResourceAsStream(this.val$name);
        }
    }

    class AnonymousClass3 implements PrivilegedAction {
        private final /* synthetic */ ClassLoader val$cl;
        private final /* synthetic */ String val$name;

        AnonymousClass3(ClassLoader classLoader, String str) {
            this.val$cl = classLoader;
            this.val$name = str;
        }

        public Object run() {
            URL[] ret = null;
            try {
                List v = new ArrayList();
                Enumeration e = this.val$cl.getResources(this.val$name);
                while (e != null && e.hasMoreElements()) {
                    URL url = (URL) e.nextElement();
                    if (url != null) {
                        v.add(url);
                    }
                }
                if (v.size() > 0) {
                    return (URL[]) v.toArray(new URL[v.size()]);
                }
                return ret;
            } catch (IOException e2) {
                return ret;
            } catch (SecurityException e3) {
                return ret;
            }
        }
    }

    class AnonymousClass4 implements PrivilegedAction {
        private final /* synthetic */ String val$name;

        AnonymousClass4(String str) {
            this.val$name = str;
        }

        public Object run() {
            URL[] ret = null;
            try {
                List v = new ArrayList();
                Enumeration e = ClassLoader.getSystemResources(this.val$name);
                while (e != null && e.hasMoreElements()) {
                    URL url = (URL) e.nextElement();
                    if (url != null) {
                        v.add(url);
                    }
                }
                if (v.size() > 0) {
                    return (URL[]) v.toArray(new URL[v.size()]);
                }
                return ret;
            } catch (IOException e2) {
                return ret;
            } catch (SecurityException e3) {
                return ret;
            }
        }
    }

    class AnonymousClass5 implements PrivilegedExceptionAction {
        private final /* synthetic */ URL val$url;

        AnonymousClass5(URL url) {
            this.val$url = url;
        }

        public Object run() throws IOException {
            return this.val$url.openStream();
        }
    }

    public static ClassLoader getContextClassLoader() {
        return (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
                ClassLoader cl = null;
                try {
                    cl = Thread.currentThread().getContextClassLoader();
                } catch (SecurityException e) {
                }
                return cl;
            }
        });
    }

    public static InputStream getResourceAsStream(Class c, String name) throws IOException {
        try {
            return (InputStream) AccessController.doPrivileged(new AnonymousClass2(c, name));
        } catch (PrivilegedActionException e) {
            throw ((IOException) e.getException());
        }
    }

    public static URL[] getResources(ClassLoader cl, String name) {
        return (URL[]) AccessController.doPrivileged(new AnonymousClass3(cl, name));
    }

    public static URL[] getSystemResources(String name) {
        return (URL[]) AccessController.doPrivileged(new AnonymousClass4(name));
    }

    public static InputStream openStream(URL url) throws IOException {
        try {
            return (InputStream) AccessController.doPrivileged(new AnonymousClass5(url));
        } catch (PrivilegedActionException e) {
            throw ((IOException) e.getException());
        }
    }
}
